home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)forms.c V1.18 3/13/95";
- #endif
- /*
- | file -- forms.c
- |======================================================================
- |
- | This example shows how to create a text entry "form". The
- | form items are entered using text entry input objects. The
- | input object named "Item1" is the starting entry item in the
- | form. The user may move forwards through the form by using
- | the <TAB> key and backwards using the <LINE FEED> key.
- |
- | The program loads a view created in DV-Draw that has text
- | entry input objects named "Item#". Each of these objects
- | is extracted from the drawing and it's bounding box is
- | found and saved. The bounding box information is used when
- | drawing an outline to highlight the current text entry field
- | as well as to focus keyboard input for the current input object.
- |
- | Keyboard focus is done by changing the x,y position of the
- | location object before passing it on to the handler,
- | VUerHandleLocEvent. The position is changed to be the center
- | of the current text entry field. Therefore, regardless of the
- | cursor position, keyboard entry will appear in the currently
- | highlighted text entry field.
- |
- | The left mouse button is used to position the carat within the
- | current text entry input object. The left mouse button event
- | is only used if position of the cursor is within the currently
- | highlighted text entry input object.
- |
- | To exit the program, use the right mouse button or select the
- | <ESC> key.
- |
- |=======================================================================
- */
- #include <windows.h>
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "forms.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define NUM_OF_TEXT_AREAS 8
- #define XK_BackSpace 0x08
- #define XK_Tab 0x09
- #define XK_Linefeed 0x0A
- #define XK_Escape 0x1B
-
- /* Whole world rectangle, (-16384, -16384) to (16383, 16383)*/
- RECTANGLE whole_world = {XMIN, YMIN, XMAX, YMAX};
-
- /* Bounding areas around text entry input objects and the center
- point of these areas */
- RECTANGLE TextArea[NUM_OF_TEXT_AREAS];
- DV_POINT TextAreaCenter[NUM_OF_TEXT_AREAS];
-
-
- /* Functions defined in forms.c */
- void Outline V_P_((DRAWPORT dp, OBJECT obj, int index));
-
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
- /*
- * program arguments
- * argv[1] - display device name (default is to use DVDEVICE)
- */
-
- /* Define & initialize device name and view filename */
- char *device_name = DVDEVICE; /* default device name */
- char *view_name = VIEW_NAME; /* default view name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- DRAWPORT drawport; /* how & where to display picture, picture frame */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
-
- /* Other variables */
- OBJECT drawing, /* graphical representation of screen */
- obj, /* object from drawing */
- outline, /* highlight object - rectangle */
- xform; /* transformation object */
- int current, /* tag for current text entry input object */
- i, /* counter */
- keysym; /* selected key symbol */
- int Quit = NO; /* flag to exit the program */
- DV_POINT scs; /* screen coordinate point */
- DV_POINT *wpt; /* world coordinate point of location object */
- WINEVENT *we; /* structure storing details of event */
- RECTANGLE dummy; /* offset which is not used */
- char obj_name[100]; /* part of names of objects in drawing */
-
- /*--------------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit( DVPATH, DISPFORMS_STB );
-
- /*
- * TscOpenSet: open a device as a screen object using
- * specified attributes
- * TscErase: erase the entire screen in the default
- * background color
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
- TscErase (screen);
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE |
- V_BUTTONPRESS | V_BUTTONRELEASE |
- V_RESIZE | V_EXPOSE,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view in from a file
- * TdpCreate: Create a DV-Tools window, a drawport.
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- */
- view = TviLoad (view_name);
- if (!view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name);
- S_EXIT (EXIT_ERR);
- }
- drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, &whole_world);
-
- /*
- * TviGetDrawing: Gets a view's drawing object
- * TdpGetXform: Get drawport transformation
- * TdpDraw: Draw contents of drawport
- */
- drawing = TviGetDrawing (view);
- xform = TdpGetXform (drawport, DR_TO_SCREEN);
- TdpDraw (drawport);
-
- /*
- * TdrGetNamedObject: Gets a named object from a
- * drawing.
- * VOobBox: Gets an object's bounding box
- *
- * Get the text input objects and store the bounding
- * box for each of these text input objects.
- */
- for (i = 0; i < NUM_OF_TEXT_AREAS; i++)
- {
- sprintf (obj_name, "Item%d", i + 1);
- obj = TdrGetNamedObject (drawing, obj_name);
- VOobBox (obj, &TextArea[i], &dummy);
- TextAreaCenter[i].x = (TextArea[i].ll.x + TextArea[i].ur.x) / 2;
- TextAreaCenter[i].y = (TextArea[i].ll.y + TextArea[i].ur.y) / 2;
- }
-
- /*
- * Get the named object "outline" which will be used to
- * highlight the current text entry input object.
- */
- outline = TdrGetNamedObject (drawing, "outline");
- current = 0;
- Outline (drawport, outline, current);
-
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- * The polling mode used is V_WAIT.
- * Therefore, VOloWinEventPoll does not
- * return until a masked event is
- * generated. V_WAIT always produces
- * a valid location object.
- */
- location = VOloWinEventPoll (V_WAIT);
-
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- */
- TscReset (screen);
- break;
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- */
- keysym = (int)VOloKeySym (location);
- switch (keysym)
- {
- case XK_Escape:
- Quit = YES;
- break;
-
- case XK_Tab:
- if (current < NUM_OF_TEXT_AREAS - 1)
- current++;
- else
- current = 0;
- Outline (drawport, outline, current);
- break;
-
- case XK_Linefeed:
- if (current > 0)
- current--;
- else
- current = NUM_OF_TEXT_AREAS - 1;
- Outline (drawport, outline, current);
- break;
-
- /*
- * VOloWinEventGet: Returns the window event structure of
- * the location object
- * VOxfPoint: Transforms point according to the
- * transform object
- * TloWinEventSetup: Sets up location object WINEVENT values
- * VUerHandleLocEvent: Service event
- *
- * Modify the location objects window event structure.
- * Change the location of the cursor to represent a
- * position in the center of the current text entry field.
- */
- default:
- we = (WINEVENT *) VOloWinEventGet (location);
- scs = TextAreaCenter[current];
- VOxfPoint (xform, &scs);
- we->loc.x = scs.x;
- we->loc.y = scs.y;
- TloWinEventSetup (location, we, screen, drawport);
- VUerHandleLocEvent (location);
- break;
- }
- break;
-
- case V_BUTTONPRESS:
- /*
- * VOloButton: Returns the button that was pressed
- *
- * The right mouse button exits the program.
- */
- switch (VOloButton (location))
- {
- case 1:
- wpt = VOloWcpGet (location);
- if (TextArea[current].ll.x <= wpt->x &&
- TextArea[current].ll.y <= wpt->y &&
- wpt->x <= TextArea[current].ur.x &&
- wpt->y <= TextArea[current].ur.y)
- VUerHandleLocEvent (location);
- break;
-
- case 3:
- Quit = YES;
- break;
- }
- break;
-
- default:
- break;
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
- }
-
- /*--------------------
- * Termination
- *
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscCloseCurrentScreen: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TdpDestroy (drawport);
- TviDestroy (view);
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-
- /*----------
- * Outline -- highlight the current text entry input object
- * by drawing a box around it. The outline object
- * is moved from the previous highlighted text
- * input object to the new current text input object.
- * The bounding box is extended to be outside the
- * object.
- */
- void
- Outline (dp, obj, index)
- DRAWPORT dp;
- OBJECT obj;
- int index;
- {
- TdpEraseObject (dp, obj);
- VOptMove (VOobPtGet (obj, 1), DV_ABSOLUTE,
- (TextArea[index].ll.x - 200),
- (TextArea[index].ll.y - 200));
- VOptMove (VOobPtGet (obj, 2), DV_ABSOLUTE,
- (TextArea[index].ur.x + 200),
- (TextArea[index].ur.y + 200));
- TdpDrawObject (dp, obj);
- }
-